package com.ssm.study.utils;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by bevin on 2017/4/29.
 */


public class Role {

    // 生产商，批发商，经销商，零售商
    public static enum roleTypeEnum {PRODUCER, WHOLESALER, DISTRIBUTOR, DEALER};

    //所属游戏的uuid
    private String uuid;

    //前一个角色
    private Role previousRole = null;

    //后一个角色
    private Role nextRole = null;

    // 标记当前role类型
    private roleTypeEnum roleType;

    // 标记当前role名
    private String roleName;

    //用tick标记当前周数
    private int tick;

    //标记当前周需求
    public HashMap<Integer, Integer> requirements;

    //每周的库存/缺货数据
    private class ChainData{
        //库存量
        public float inventory;

        //缺货量
        public float stockout;

        public ChainData(){};

        public ChainData(float inventory, float stockout){
            this.inventory = inventory;
            this.stockout = stockout;
        };

        public ChainData copy(){
            return new ChainData(inventory, stockout);
        }

        public void update(float in, float out){
            inventory = inventory + in - out - stockout;
            if (inventory < 0){
                stockout = inventory;
                inventory = 0;
            }
            else{
                stockout = 0;
            }
        }
    }

    //记录当前周的库存/缺货数据
    private ChainData currentChainData;

    //历史数据 <tick, ChainData>
    private Map<Integer, ChainData> historyChainData;

    public Role(String uuid, roleTypeEnum roleType, String roleName){
        this.uuid = uuid;
        this.roleType = roleType;
        this.roleName = roleName;
        tick = 0;
    }

    public void nextTick(){
        ++tick;

        historyChainData.put(tick, currentChainData.copy());
        //float in = previousRole.
        //currentChainData.update();
    }

    public int getTick(){
        return tick;
    }

    public String getUuid() {
        return uuid;
    }

    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    public roleTypeEnum getRoleType() {
        return roleType;
    }

    public void setRoleType(roleTypeEnum roleType) {
        this.roleType = roleType;
    }

    public String getRoleName() {
        return roleName;
    }

    public void setRoleName(String roleName) {
        this.roleName = roleName;
    }

    public ChainData getCurrentChainData() {
        return currentChainData;
    }

    public void setCurrentChainData(ChainData currentChainData) {
        this.currentChainData = currentChainData;
    }

    public Role getPreviousRole() {
        return previousRole;
    }

    public void setPreviousRole(Role previousRole) {
        this.previousRole = previousRole;
    }

    public Role getNextRole() {
        return nextRole;
    }

    public void setNextRole(Role nextRole) {
        this.nextRole = nextRole;
    }

    public int getCurrentRequirement() {
        if(requirements.containsKey(tick)){
            return requirements.get(tick);
        }
        return -1;
    }

}
